#!/bin/bash
. lib.sh
direct_url="https://mirrors.aliyun.com/goproxy/"
string1="构建失败，请检查后重试！"
string2="克隆失败，请检查后重试！"
string3="构建完成✅，正在复制可执行文件到bin目录..."
string4="复制完成✅"
string5="输入 ncmdump 加上要转换的.ncm文件试用！"
string6="使用 ncmdump --help 查看帮助！"
function golang_install_termux {
	pkg_install golang
}
function golang_install_debian {
	apt_install golang
}
function main {
	cd ../
	if ! [[ -d "ncmdump" ]]; then
		git clone git@gitee.com:aiba51/ncmdump.git
	fi
	if [[ $? -eq 0 ]]; then
		cd ncmdump
		go env -w GOPROXY="$direct_url",direct
		go mod tidy
		go build -o ncmdump ./cmd/ncmdump/main.go
		if [[ $? -eq 0 ]]; then
			echo "$string3"
			if echo "$system_info" | grep -q "Android";
			then
				cp ncmdump "$install_termux_dir"
			else
				cp ncmdump "$install_debian_dir"
			fi
			echo -e "$string4\n$string6\n$string5"
		else
			echo "$string1"
			exit 1
		fi
	else
		echo "$string2"
		exit 1
	fi
}
judgment "go" golang_install_termux golang_install_debian
judgment_main "golang"
